<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <div class="hello">
    Hello word!
  </div>
  用户名：
  <input type="text" id="username"> 密码：
  <input type="password" id="password">
  <button id="login">登录</button>

  <br>
  <input type="file" id="file" accept="*" />

</body>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
<script type="text/javascript">

  var contextPath = 'http://localhost:3000'

  $('.hello').on('click', function () {
    $.ajax({
      type: 'get',
      url: '/api/string/123',
      data: { name: 'a' },
      success: function (data) {
        console.log(data);
      },
      error: function (data) {
        console.log(data);
      }

    })
  })

  // 登录
  $('#login').on('click', function () {
    var username = $('#username').val()
    var password = $('#password').val()
    $.ajax({
      type: 'post',
      url: '/api/login',
      data: { username: username, password: password },
      success: function (data) {
        console.log(data);
      },
      error: function (data) {
        console.log(data);
      }

    })
  })

  // file
  $('#file').on('change', function (e) {
    let files = e.target.files[0]
    var formFile = new FormData();
    formFile.append("action", "UploadVMKImagePath");
    formFile.append("file", files); //加入文件对象
    var data = formFile;
    $.ajax({
      type: 'post',
      url: '/api/upload',
      data: data,
      dataType: "json",
      cache: false,//上传文件无需缓存
      processData: false,//用于对data参数进行序列化处理 这里必须false
      contentType: false, //必须 
      success: function (data) {
        console.log(data);
      },
      error: function (data) {
        console.log(data);
      }

    })
  })




  setTimeout(()=>{console.log(1)},0)
  new Promise(function(resolve,reject){

    $.ajax({
      type: 'get',
      url: '/api/string/123',
      data: { name: 'a' },
      success: function (data) {
        resolve();
        console.log(2)
        console.log(data);
      },
      error: function (data) {
        console.log(data);
      }

    })
            
    }).then(()=>{
        console.log(3)
    })
  console.log(4)
       

</script>

</html>